package com.squapsource.project_euler;

import java.util.List;

import com.squapsource.project_euler.utils.PrimesUtility;

public class Problem27 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		List<Long> primes = PrimesUtility.getPrimesUpToMax(10000000);
		int maxPrimes = 0;
		int maxA = 0;
		int maxB = 0;
		for (int a = -999; a < 1000; a++) {
			for (int b = -999; b < 1000; b++) {
				int n =0;
				while (true) {
					if (!PrimesUtility.isPrime(n * n + a * n + b, primes)) {
						break;
					}
					n++;

				}
				if (n > maxPrimes) {
					maxPrimes = n;
					maxA = a;
					maxB = b;
				}
			}
		}
		System.out.println(maxA*maxB + " " + maxA + " " + maxB + " " + maxPrimes);
	}

}
